package cn.iocoder.yudao.module.promotion.groupon.dao;

import cn.iocoder.yudao.framework.business.basic.dao.mapper.CoreMapper;
import cn.iocoder.yudao.framework.business.basic.dao.query.CoreLambdaQueryWrapper;
import cn.iocoder.yudao.module.promotion.groupon.pojo.po.GrouponProduct;
import org.apache.ibatis.annotations.Mapper;

import java.util.ArrayList;
import java.util.List;
import java.util.Set;

/**
 * <pre>
 * OOoO0OOoO0OOOooo0oOOOO0OOOOO0oooOO0ooOOO0Ooooo0OOOOo0ooooO0OOooo0Ooooo0OOOOO
 *  这里是文件说明
 * OOoO0OOoO0OOOooo0oOOOO0OOOOO0oooOO0ooOOO0Ooooo0OOOOo0ooooO0OOooo0Ooooo0OOOOO
 * </pre>
 *
 * @author 山野羡民（1032694760@qq.com）
 * @since 2025/01/13
 */
@Mapper
public interface GrouponProductMapper extends CoreMapper<GrouponProduct> {

    default List<GrouponProduct> selectListByPackageId(Long packageId) {
        CoreLambdaQueryWrapper<GrouponProduct> wrapper = new CoreLambdaQueryWrapper<>();
        wrapper.eq(GrouponProduct::getPackageId, packageId);
        return selectList(wrapper);
    }

    default List<GrouponProduct> selectListByPackageIds(Set<Long> packageIds) {
        if (packageIds == null || packageIds.isEmpty()) {
            return new ArrayList<>();
        }
        CoreLambdaQueryWrapper<GrouponProduct> wrapper = new CoreLambdaQueryWrapper<>();
        if (packageIds.size() == 1) {
            wrapper.eq(GrouponProduct::getPackageId, packageIds.iterator().next());
        } else {
            wrapper.in(GrouponProduct::getPackageId, packageIds);
        }
        return selectList(wrapper);
    }

    default void deleteByPackageIdAndSkuId(Long packageId, Long skuId, Long shopId) {
        CoreLambdaQueryWrapper<GrouponProduct> wrapper = new CoreLambdaQueryWrapper<>();
        delete(wrapper.eq(GrouponProduct::getPackageId, packageId)
                .eq(GrouponProduct::getSkuId, skuId)
                .eq(GrouponProduct::getShopId, shopId));
    }

    default void deleteByPackageId(Long packageId, Long shopId) {
        CoreLambdaQueryWrapper<GrouponProduct> wrapper = new CoreLambdaQueryWrapper<>();
        delete(wrapper.eq(GrouponProduct::getPackageId, packageId)
                .eq(GrouponProduct::getShopId, shopId));
    }

}
